package com.miukoo.aikao.metadata.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.miukoo.aikao.core.dtos.ApiResult;
import com.miukoo.aikao.core.dtos.PageReqDto;
import com.miukoo.aikao.core.dtos.PageResDto;
import com.miukoo.aikao.core.utils.ApiUtils;
import com.miukoo.aikao.core.utils.BeanMapperUtils;
import com.miukoo.aikao.metadata.dto.SysRoleDto;
import com.miukoo.aikao.metadata.pojos.SysRole;
import com.miukoo.aikao.metadata.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 管理用户控制器
 * </p>
 *
 * @author 聪明笨狗
 * @since 2020-04-13 16:57
 */
@Api(tags = {"管理用户"})
@RestController
@RequestMapping("/exam/api/sys/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;




    /**
     * 分页查找
     * @param reqDto
     * @return
     */
    @ApiOperation(value = "分页查找")
    @RequestMapping(value = "/paging", method = { RequestMethod.POST})
    public ApiResult<PageResDto<List<SysRole>>> paging(@RequestBody PageReqDto<SysRoleDto> reqDto) {

        //分页查询并转换
        PageResDto<List<SysRole>> page = sysRoleService.paging(reqDto);
        return ApiUtils.success(page);
    }

    /**
     * 查找列表，每次最多返回200条数据
     * @return
     */
    @ApiOperation(value = "查找列表")
    @RequestMapping(value = "/list", method = { RequestMethod.POST})
    public ApiResult<List<SysRoleDto>> list() {

        //分页查询并转换
        QueryWrapper<SysRole> wrapper = new QueryWrapper<>();

        //转换并返回
        List<SysRole> list = sysRoleService.list(wrapper);

        //转换数据
        List<SysRoleDto> dtoList = BeanMapperUtils.mapList(list, SysRoleDto.class);

        return ApiUtils.success(dtoList);
    }
}
